<?php

class system_cron {
	
	public function __construct () {}
	
	public function __default () {}
	
	public function thumbs () {
		if (!is_dir (DOC_ROOT . '/images/thumbs')) {
			return;
		}
		
		$aFiles = scandir (DOC_ROOT . '/images/thumbs');
	
		foreach ($aFiles as $item) {
			if ($item == 'index.html' || substr ($item, 0, 1) == '.') {
				continue;
			}
			
			if (is_file (DOC_ROOT . '/images/thumbs/' . $item)) {
				unlink (DOC_ROOT . '/images/thumbs/' . $item);
			}
		}
	}
	
	public function mail () {
		$oTypeMail = TypesController::getInstance()->getTypeByName ('email');
		$objectsController = ObjectsController::getInstance ();
		
		$sel = new Selection ();
		$sel->addType ($oTypeMail);
		if (getRequest ('max', 'bool')) {
			$sel->addLimit (getRequest ('max', 'int'));
		}
		
		$aObjects = $objectsController->getObjectsList($sel->getList ());
		
		foreach ($aObjects as $object) {
			$oEmail = new EMail ();
			$oEmail->setAddress ($object->getValue ('address'));
			$oEmail->setBody ($object->getValue ('body'));
			$oEmail->setSubject ($object->getValue ('subject'));
			
			if (Mailer::sendEMail ($oEmail, true)) {
				$object->delete ();
			}
		}
	}
	
}